<?php

//115 	http://ruseller.com/lessons.php?rub=1&id=65
    echo "
<!DOCTYPE html>
<html lang='ru'>
<head>
    <meta charset='windows-1251' />
    
</head>
<body>";
//<meta http-equiv='refresh' content='10'>
    
for ($i=1;$i<500000;$i++)    {

//echo get76from10(5776);
    $int = $i;
    $utf = iconv("UTF-8", "WINDOWS-1251", get76from10($int));
    $ddd = get10from76(iconv("WINDOWS-1251", "UTF-8", $utf)).")<hr>";
    if ( (int)$ddd == (int)$int){}
    else
        echo $int." -> (".$utf." :: ".$ddd.")<hr>";

// http://partners.academic.ru/partner/selecturl.php?addrec=1
}



echo "</body>";


function get76from10( $arg ){
    $chars = array(
        '0','1','2','3','4','5','6','7','8','9',
        'ё','й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф',
        'ы','в', 'а','п','р','о','л','д','ж','э', 'я','ч','с','м','и','т',
        'ь','б','ю',
        'Ё','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф',
        'Ы','В', 'А','П','Р','О','Л','Д','Ж','Э', 'Я','Ч','С','М','И','Т',
        'Ь','Б','Ю');

    if ($arg < 76) {
        $result = $chars[$arg];
    }
    else if ($arg < 76*76) {
        $res[int] = (int) ($arg/76);
        $res[mod] = $arg%76;

        $result = $chars[$res[int]].$chars[$res[mod]];
    }
    else if ($arg < 76*76*76) {

        $res[int] = (int) ($arg/76);
        $res[mod][0] = $arg%76;

        $arg = $res[int];

        $res[int] = (int) ($arg/76);
        $res[mod][1] = $arg%76;

        $arg = $res[int];

        //$res[mod][2] = (int) ($arg/76);
        $res[mod][2] = (int) $res[int];

        //echo $res[mod][0].$res[mod][1].$res[mod][2]."<br>";

        $result = $chars[$res[mod][2]].$chars[$res[mod][1]].$chars[$res[mod][0]];
    }
    else {
        exit;
    }

    return $result;
}


function xchar($str, $pos) {
    return mb_substr($str,$pos-1,1,'UTF-8');
}

function get10from76( $arg ){
    $chars = array(
        '0','1','2','3','4','5','6','7','8','9',
        'ё','й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф',
        'ы','в', 'а','п','р','о','л','д','ж','э', 'я','ч','с','м','и','т',
        'ь','б','ю',
        'Ё','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф',
        'Ы','В', 'А','П','Р','О','Л','Д','Ж','Э', 'Я','Ч','С','М','И','Т',
        'Ь','Б','Ю');

    //echo mb_strwidth($arg, 'UTF-8')."<br>";
    if( mb_strwidth($arg, 'UTF-8') == 1) {
        $result = array_search(xchar($arg,0), $chars);
    }
    else if ( mb_strwidth($arg, 'UTF-8') == 2) {
        $key1 = array_search(xchar($arg,0), $chars);
        $key2 = array_search(xchar($arg,1), $chars);

        $result = $key1 + $key2*76;
    }
    else if ( mb_strwidth($arg, 'UTF-8') == 3) {
        //echo sprintf("%d %d %d",$key1,$key2,$key3)."<br>";
        if( is_numeric ($arg) ) {
            $key1 = $arg{0};
            $key2 = $arg{1};
            $key3 = $arg{2};
        }
        else {
            $key1 = array_search(xchar($arg,1), $chars);
            $key2 = array_search(xchar($arg,2), $chars);
            $key3 = array_search(xchar($arg,0), $chars);
        }

        //echo sprintf("%d %d %d",$key1,$key2,$key3)."<br>";

        $result = ((int)$key3) + ((int)$key2)*76 + ((int)$key1)*76*76;
    }
    else {
        exit;
    }

    return $result;
}
?>